package com.house.keeper.controller;

import com.alibaba.fastjson.JSONObject;
import com.house.keeper.base.BaseController;
import com.house.keeper.base.Result;
import com.house.keeper.entity.vo.CommunityPersonVo;
import com.house.keeper.entity.CommunityPerson;
import com.house.keeper.service.CommunityPersonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.ModelAndView;
import org.apache.shiro.authz.annotation.RequiresPermissions;

/**
 * @author zjj
 * @date 2022-06-01 08:42:42
 *
 * @description 
 */
@Slf4j
@Controller
@RequestMapping("/communityPerson")
public class CommunityPersonController extends BaseController {

    @Autowired
    private CommunityPersonService communityPersonService;

    /**
      * 跳转到管理页面
      * @return
      */
    @GetMapping(value = "/view")
    @RequiresPermissions("system:communityPerson:view")
    public ModelAndView view(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("communityPerson/list");
        return modelAndView;
    }
    /**
     * 分页查询
     * @param communityPersonVo 查询条件
     * @return
     */
    @GetMapping(value = "/list")
    @RequiresPermissions("system:communityPerson:list")
    @ResponseBody
    public JSONObject list(CommunityPersonVo communityPersonVo){
        Result result=communityPersonService.selectByPage(communityPersonVo);
        return responseJSONObject(result);
    }

    /**
     * 新增或修改
     * @param communityPerson
     * @return
     */
    @PostMapping(value = "/update")
    @RequiresPermissions("system:communityPerson:edit")
    @ResponseBody
    public JSONObject edit(@RequestBody CommunityPerson communityPerson){
        Result result = communityPersonService.update(communityPerson);
        return responseJSONObject(result);
    }

    /**
     * 删除
     * @param id id
     * @return
     */
    @GetMapping(value = "/delete")
    @RequiresPermissions("system:communityPerson:del")
    @ResponseBody
    public JSONObject edit(Integer id){
        Result result = communityPersonService.delete(id);
        return responseJSONObject(result);
    }
}

